npm run<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-input v-model="filters.keyword" placeholder="关键字"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="search">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>
		<!--列表-->
		<el-table :data="logs" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
			<el-table-column type="selection" width="55">
			</el-table-column>
			<el-table-column type="index" width="60">
			</el-table-column>
			<el-table-column prop="username" label="名称" width="100" sortable>
			</el-table-column>
			<el-table-column prop="state" label="状态" width="100" sortable>
        <template scope="scope">
          <span v-if="scope.row.state == '执行成功！'" style="color: green">执行成功</span>
          <span v-else-if="scope.row.state == '执行失败'" style="color: red">执行失败</span>
          <span v-else style="color: dimgrey">未知操作</span>
        </template>
			</el-table-column>
			<el-table-column prop="description" label="方法描述" width="160" sortable>
			</el-table-column>
			<el-table-column prop="method" label="方法" width="160" sortable>
			</el-table-column>
			<el-table-column prop="url" label="请求路径" width="160" sortable>
			</el-table-column>
			<el-table-column prop="ip" label="ip地址" width="160" sortable>
			</el-table-column>
			<el-table-column prop="runtime" label="运行时长" width="160" sortable>
			</el-table-column>
			<el-table-column prop="createTime" label="操作时间" width="160" sortable>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-pagination layout="prev, pager, next, sizes" background
                     @size-change="handleSizeChange"
                     @current-change="handleCurrentChange"
                     :page-size="pageSize"
                     :page-sizes="pageSizes"
                     :total="total"
                     :current-page="currentPage"
                     style="float:right;">
			</el-pagination>
		</el-col>
	</section>
</template>

<script>
	export default {
		data() {
			return {
        title:"",
				filters: {
          keyword: ''
				},
				logs: [],
				total: 0,
				currentPage: 1,
        pageSize: 10,
        pageSizes: [5, 10, 15, 20],
				listLoading: false,
			}
		},
		methods: {
      handleSizeChange(val) {
        this.pageSize = val;
        this.getLogs();
      },
      search() {
        this.currentPage = 1;
        this.getLogs();
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        this.getLogs();
      },
      //获取日志列表
      getLogs() {
        let para = {
          currentPage: this.currentPage,
          pageSize: this.pageSize,
          keyword: this.filters.keyword
        };
        this.listLoading = true;
        this.$http.post("/log/page", para)
            .then(result => {
              console.log(result)
              this.listLoading = false;
              result = result.data;
              this.logs = result.rows;
              this.total = result.total;
              console.log(this.logs)
            })
            .catch(result => {
              console.log(result);
              this.$message({
                type: 'error',
                message: '系统错误,我们正在殴打程序员'
              })
            })
      },
    },
		mounted() {
			this.getLogs();
		}
	}

</script>

<style scoped>

</style>